package com.all.jpa.servvice.impl;

import com.all.jpa.repository.SysUserRepository;
import com.all.jpa.model.entity.SysUser;
import com.all.jpa.servvice.ISysUserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @Author LY
 * @create 2024/4/26 15:28
 * @Description 用户信息表 服务实现类
 */
@Service
public class SysUserServiceImpl implements ISysUserService {

    @Resource
    private SysUserRepository sysUserRepository;

    @Override
    public SysUser findById(Long userId) {
        return sysUserRepository.findById(userId).get();
    }

    @Override
    public List<SysUser> findAll() {
        return sysUserRepository.findAll();
    }

    @Override
    public List<Map<String,Object>> findByName(String name) {
        return sysUserRepository.findByUserName(name);
    }

    @Override
    public void save() {
        SysUser user = new SysUser();
        user.setUserId(3L);
        user.setUserName("rrr");
        user.setNickName("rrr");
        user.setCreateBy("admin");
        user.setCreateTime(LocalDateTime.now());
        sysUserRepository.save(user);
    }

    @Override
    public void delete(Long userId) {
        sysUserRepository.deleteById(userId);
    }

    @Override
    public List<SysUser> findByUserName2(String userName) {
        return sysUserRepository.findByUserName2(userName);
    }

}
